<?php

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Models\BingRen;
use App\Models\TiWen;
use Illuminate\Http\Request;

class HomeController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //$this->middleware('auth');
    }

    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        return view('home.tiwen');
    }

    public function add_tiwen(Request $request)
    {
        $tiwen = $request->input('tiwen');
        $xueyang = $request->input('xueyang');
        $bingren = BingRen::where('status',1)->take(5)->pluck('id');

        foreach ($tiwen as $k => $v){
            $info = new TiWen();
            $info->bingren_id = $bingren[$k];   //id为1,2,3,4,5
            $info->tiwen = $v;
            $info->xueyang = $xueyang[$k];
            $info->ctime = date('Y-m-d');
            $info->save();
        }
        return redirect('home/index');

    }
}
